<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/26 0026
 * Time: 上午 9:35
 */

namespace App\Http\Controllers\Coin;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    /**
     * 绑定账户信息
     * @date 2018/03/26
     * @author yanggang
     * @param Request $request
     * @return array
     */
    public function bindPayInfo(Request $request)
    {
        $type = $request->get('type');

        if (!isset($type)) {
            return respF(1003);
        }
        $params = $request->all();

        (new User())->savePayInfo($params);

        return ['status'=>1,'msg'=>'操作成功'];
    }

    /**
     * 获取绑定的账户信息
     * @date 2018/03/26
     * @author yanggang
     * @param Request $request
     * @return array
     */
    public function getPayInfo(Request $request)
    {
        $id = $request->get('uid');
        if (empty($id)) {
            return respF(1003);
        }
        
        $list = User::select('id', 'account')->where('id', $id)->with([
            'user_bank:id,uid,bank_name,bank_no,bank_info',
            'user_alipay:id,uid,alipay_account,alipay_code',
            'user_wechat:id,uid,wechat_account,wechat_code',
        ])->first();
        
        if (!$list) {
            $list = [];
        } else {

            $list = $list->toArray();
            if (!$list['user_bank']){
                $list['user_bank'] = (object)[];
            }
            if ($list['user_alipay']){
                $list['user_alipay']['alipay_code'] = empty($list['user_alipay']['alipay_code'])?'':config('alioss.host').'/'.$list['user_alipay']['alipay_code'];
            }else{
                $list['user_alipay'] = (object)[];
            }
            if ($list['user_wechat']){
                $list['user_wechat']['wechat_code'] = empty($list['user_wechat']['wechat_code'])?'':config('alioss.host').'/'.$list['user_wechat']['wechat_code'];
            }else{
                $list['user_wechat'] = (object)[];
            }

        }

        return ['status'=>1,'msg'=>'成功','data'=>$list];
    }
}
